<?php
    header("content-type:text/html;charset=utf-8");
    
    $mem = new Memcache;
    $mem->addServer('127.0.0.1','11211');

    
    $sql = "select * from user";
    $key = md5($sql);
    echo $key;

    //尝试从缓存获取
    $list = $mem->get($key);
    if(!$list){
        //没有缓存
        mysql_connect('localhost','root','123456');
        mysql_select_db('project21');
        mysql_set_charset('utf8');

        sleep(5);
        $result = mysql_query($sql);
        if($result){
            while($row = mysql_fetch_assoc($result)){
                $list[] = $row;
            }

            //存一份  作为缓存  以便下次使用
            $mem->set($key,$list,2,10);
        }
    }


    echo "<pre>";
        print_r($list);
    echo "</pre>";



?>
